package com.aaa.vip.service.impl;

import com.aaa.common.entity.UserIntegralLog;
import com.aaa.common.util.TokenUtil;
import com.aaa.vip.dao.UserIntegralLogDao;
import com.aaa.vip.service.UserIntegralLogService;
import org.springframework.stereotype.Service;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.aaa.common.util.CustomException;
import com.aaa.common.util.ResultStatus;
import com.aaa.common.vo.Page;


import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * 积分记录表详情(UserIntegralLog)表服务实现类
 *
 * @author makejava
 * @since 2025-09-22 11:02:27
 */
@Service("userIntegralLogService")
public class UserIntegralLogServiceImpl implements UserIntegralLogService {
    @Resource
    private UserIntegralLogDao userIntegralLogDao;
    @Resource
    private HttpServletRequest request;

    @Override
    public List<UserIntegralLog> selectAllScore() {
        String userId = TokenUtil.getUserId(request);
        return userIntegralLogDao.selectAllScore(Integer.valueOf(userId));
    }
    @Override
    public List<UserIntegralLog> selectArrivalScore() {
        String userId = TokenUtil.getUserId(request);
        return userIntegralLogDao.selectArrivalScore(Integer.valueOf(userId));
    }
    @Override
    public List<UserIntegralLog> selectExpendScore() {
        String userId = TokenUtil.getUserId(request);
        return userIntegralLogDao.selectExpendScore(Integer.valueOf(userId));
    }

    /**
     * 通过ID查询单条数据
     *
     * @param integralLogId 主键
     * @return 实例对象
     */
    @Override
    public UserIntegralLog queryById(Integer integralLogId) {
        return this.userIntegralLogDao.queryById(integralLogId);
    }

    /**
     * 分页查询
     *
     * @param page 筛选条件
     * @return 查询结果
     */
    @Override
    public PageInfo queryByPage(Page<UserIntegralLog> page) {
        //分页操作  分页参数一定要进行传递
        if (page == null || page.getPageNo() == null || page.getPageNo() == 0 || page.getPageSize() == null || page.getPageSize() == 0) {
            //进行业务编写时，可以抛出自定义异常
            throw new CustomException(ResultStatus.PARAM_NOT_EMPTY.getReturnCode(),
                    ResultStatus.PARAM_NOT_EMPTY.getReturnMessage());
        }
        PageHelper.startPage(page.getPageNo(), page.getPageSize());
        //获取查询对象
        UserIntegralLog userIntegralLog = page.getData();
        return new PageInfo(userIntegralLogDao.queryAllByLimit(userIntegralLog));
    }

    /**
     * 新增数据
     *
     * @param userIntegralLog 实例对象
     * @return 实例对象
     */
    @Override
    public UserIntegralLog insert(UserIntegralLog userIntegralLog) {
        this.userIntegralLogDao.insert(userIntegralLog);
        return userIntegralLog;
    }

    /**
     * 修改数据
     *
     * @param userIntegralLog 实例对象
     * @return 实例对象
     */
    @Override
    public UserIntegralLog update(UserIntegralLog userIntegralLog) {
        this.userIntegralLogDao.update(userIntegralLog);
        return this.queryById(userIntegralLog.getIntegralLogId());
    }

    /**
     * 通过主键删除数据
     *
     * @param integralLogId 主键
     * @return 是否成功
     */
    @Override
    public boolean deleteById(Integer integralLogId) {
        return this.userIntegralLogDao.deleteById(integralLogId) > 0;
    }
}
